﻿using System;
using System.Collections.Generic;
using ContactManager.Models.Entities;
using ContactManager.Models.Repositories;

using NUnit.Framework;
using NHibernate;
//using Moq;

namespace ContactManager.Tests.Models
{
    [TestFixture]
    class ContactARTestCase : AbstractModelTestCase
    {
        //private Mock<IContactManagerRepositoryAr> _repository;
        
        public ContactManagerRepositoryAr _contactController;

        

        

        
        [SetUp]
        public void Initialize()
        {
            
            //_repository = new Mock<IContactManagerRepositoryAr>();
            _contactController = new ContactManagerRepositoryAr();
        }

        [TearDown]
        public void TearDown()
        {
            //if(base.scope.base.DisposeScope();
        }


        [Test]
        public void ListContacts()
        {
           
            //FlushAndRecreateScope(); // Persist the changes as we're using scopes
            
            IList<Contact>  _contacts= _contactController.ListAll<Contact>();
            Assert.IsTrue(_contacts.Count > 0);
            }

        [Test]
        public void EditContact()
        {
            Contact contact = ContactFake.ValidContact();
            contact.LastName = "Suarez Carvajal";
            _contactController.Edit<Contact>(contact);            
            Contact _newContact = _contactController.LoadById<Contact>(contact.Id);            
            Assert.IsTrue(contact.LastName == _newContact.LastName,"Contact has been updated");
        }
    }
}

	

